﻿using System.Text;

namespace CodeContrib
{
	public class RandomPassword : IRandom<string>
	{
		private static readonly char[] _characters;
		private const int _defaultLength = 10;
		private readonly RandomItem<char> _randomCharacter;

		static RandomPassword()
		{
			_characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()".ToCharArray();
		}

		public RandomPassword()
		{
			_randomCharacter = new RandomItem<char>(_characters);
		}

		public string Next()
		{
			return Next(_defaultLength);
		}

		public string Next(int length)
		{
			var password = new StringBuilder();

			for (var i = 0; i < length; i++)
			{
				password.Append(_randomCharacter.Next());
			}

			return password.ToString();
		}
	}
}